package edu.sctu.zhuyingzhi.month201506.day20150614.fileOperationV1;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Created by user13 on 2015/6/14.
 */
public class FileUitl {

    public FileUitl(){

    }

    FileRoute fileRoute = FileRoute.getRoute();

    public boolean judgeFile(File file){
        if (!file.exists()){
            file.mkdirs();
        }
        return file.exists();
    }

    public boolean creatFile(File file1) throws IOException {



            file1.createNewFile();



        return file1.exists();
    }

    public void writeFile(File file) throws IOException {

        FileWriter out = new FileWriter(file);
        char[] data = new char[50];
        for (int i = 0; i < 50; i++) {
            data[i] = 50;
        }
        System.out.println(data);
        out.write(data, 0, data.length);
        out.flush();
        out.close();

    }

    public void copyFile(File file,File file2) throws IOException {
        FileWriter out = new FileWriter(file2);
        FileReader in = new FileReader(file);
        char[] data1 = new char[50];
        int end = in.read(data1,0,data1.length);
        out.write(data1,0,end);
        out.flush();
        out.close();
        in.close();

    }

    public void removeFile(File file,File file2) throws IOException {
        if (!fileRoute.fileA.exists()){
            fileRoute.fileA.mkdirs();

        }
        file2.createNewFile();
        System.out.println(file2);
        FileWriter out = new FileWriter(file2);
        FileReader in = new FileReader(file);
        char[] data1 = new char[50];
        int end = in.read(data1,0,data1.length);
        out.write(data1,0,end);
        out.flush();
        out.close();
        in.close();
        file.delete();
    }
    public void deleteFile(File file) throws IOException {
        if (creatFile(fileRoute.file1)){
            file.delete();
        }

    }


}
